
package com.yimixian.app.payment;

import android.text.TextUtils;

public class AlipayPayResult {

    private String mResultStatus;
    private String mResult;
    private String mMemo;

    public AlipayPayResult(String rawResult) {
        if (TextUtils.isEmpty(rawResult)) {
            return;
        }

        String[] resultParams = rawResult.split(";");
        for (String resultParam : resultParams) {
            if (resultParam.startsWith("resultStatus")) {
                mResultStatus = gatValue(resultParam, "resultStatus");
            }
            if (resultParam.startsWith("result")) {
                mResult = gatValue(resultParam, "result");
            }
            if (resultParam.startsWith("memo")) {
                mMemo = gatValue(resultParam, "memo");
            }
        }
    }

    @Override
    public String toString() {
        return "resultStatus={" + mResultStatus + "};memo={" + mMemo + "};result={" + mResult + "}";
    }

    private String gatValue(String content, String key) {
        String prefix = key + "={";
        return content.substring(content.indexOf(prefix) + prefix.length(),
                content.lastIndexOf("}"));
    }

    public String getResultStatus() {
        return mResultStatus;
    }

    public String getMemo() {
        return mMemo;
    }

    public String getResult() {
        return mResult;
    }
}
